package com.iespring.controller.app.cart;

import com.iespring.bean.app.cart.bo.*;
import com.iespring.bean.app.cart.vo.CartIndexVo;
import com.iespring.bean.app.cart.vo.CheckoutVo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.service.app.cart.WxCartService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KeFei
 * @description: 微信小程序购物车模块
 * @date 2022/12/31 16:16
 */
@RestController
@RequestMapping("wx")
public class CartController {

    @Resource
    WxCartService wxCartService;

    /**
     *
     */
    @RequestMapping("cart/goodscount")
    public BaseRespVo goodsCount() {
        // 获取购物车中的商品数量
        int cartGoodsNumber = wxCartService.getCartGoodsNumber();

        return BaseRespVo.ok(cartGoodsNumber);
    }

    /**
     * 添加购物车商品
     */
    @RequestMapping("cart/add")
    public BaseRespVo addCartGoods(@RequestBody AddCartGoodsBo addCartGoodsBo) {

        int cartGoodsNumber = wxCartService.addCartGoods(addCartGoodsBo);

        return BaseRespVo.ok(cartGoodsNumber);
    }

    /**
     * 显示购物车主页
     */
    @RequestMapping("cart/index")
    public BaseRespVo cartIndex() {

        CartIndexVo cartIndexVo = wxCartService.cartIndex();

        return BaseRespVo.ok(cartIndexVo);
    }

    /**
     * 修改购物车中某单个商品的数量
     */
    @RequestMapping("cart/update")
    public BaseRespVo updateCartGoodsNumber(@RequestBody UpdateCartGoodsNumberBo updateCartGoodsNumberBo) {

        wxCartService.updateCartGoodsNumber(updateCartGoodsNumberBo);

        return BaseRespVo.ok();
    }

    /**
     * 改变购物车中商品的选择状态
     */
    @RequestMapping("cart/checked")
    public BaseRespVo changeCheckedState(@RequestBody CheckedStateBo checkedStateBo) {

        CartIndexVo cartIndexVo = wxCartService.changeCheckedState(checkedStateBo);

        return BaseRespVo.ok(cartIndexVo);
    }

    /**
     * 立即购买商品
     */
    @RequestMapping("cart/fastadd")
    public BaseRespVo fastAdd(@RequestBody FastAddBo fastAddBo) {

        int cartId = wxCartService.fastAdd(fastAddBo);

        return BaseRespVo.ok(cartId);
    }

    /**
     * 下单结账页面
     */
    @RequestMapping("cart/checkout")
    public BaseRespVo checkout(CheckoutBo checkoutBo) {

        CheckoutVo checkoutVo = wxCartService.checkout(checkoutBo);

        return BaseRespVo.ok(checkoutVo);
    }

    /**
     * 删除购物车中的商品
     */
    @RequestMapping("cart/delete")
    public BaseRespVo deleteCartGoods(@RequestBody DeleteCartGoodsBo deleteCartGoodsBo) {

        CartIndexVo cartIndexVo = wxCartService.deleteCartGoods(deleteCartGoodsBo);

        return BaseRespVo.ok(cartIndexVo);
    }

}
